import Api from '@core/http/decorates/api';
import { AxiosInstance } from 'axios';
import { UserRes } from './models/UserRes';

@Api({ prefix: 'login' })
export class Login {
  private readonly http: AxiosInstance;

  /**
   * 登录
   *
   * @param {string} username
   * @param {string} password
   * @return {*}
   * @memberof Login
   */
  async signIn(username: string, password: string) {
    return (
      await this.http.post<UserRes>('signIn', {
        username,
        password,
      })
    ).data;
  }

  /**
   * 注册
   *
   * @param {string} username
   * @param {string} password
   * @return {*}
   * @memberof Login
   */
  async register(username: string, password: string) {
    return (
      await this.http.post<string>('register', {
        username,
        password,
      })
    ).data;
  }
}
